package com.lagou.study.order.listener;

import com.lagou.study.order.service.OrderService;
import com.lagou.study.order.service.RedisService;
import com.lagou.study.order.service.StockService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "seckill",consumerGroup = "seckill-consumer")
public class Consumer implements RocketMQListener<String>  {

    @Autowired
    private StockService stockService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private RedisService redisService;

    @Override
    public void onMessage(String id) {
        if (id != null) {
            stockService.minusOne();
            orderService.create(id);
            redisService.del("stock");
        }
    }
}
